<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增信用管理')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-credit-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">评分：</label>
            <div class="col-sm-8">
                <div class="form-group">
                    <select id="scoreTemplates" class="form-control noselect2 selectpicker" data-none-selected-text="请评分" multiple>
                        <optgroup label="--加分--" id="addST">
                            <!--<option value="Java">Java</option>
                            <option value="PHP">PHP</option>
                            <option value=".NET">.NET</option>-->
                        </optgroup>
                        <optgroup label="--扣分--" id="minusST">
                            <!--<option value="Oracle">Oracle</option>
                            <option value="Mysql">Mysql</option>
                            <option value="Sysbase">Sysbase</option>-->
                        </optgroup>
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group" hidden>
            <label class="col-sm-3 control-label is-required">用户ID：</label>
            <div class="col-sm-8">
                <input name="userId" class="form-control" type="text" th:value="${userId}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">评价内容：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control" type="text"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-select-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var prefix = ctx + "wstudy/credit"
    var prefix = ctx + "wstudy/credit"
    $("#form-credit-add").validate({
        focusCleanup: true,
        onkeyup:false,
        rules:{
            code:{
                required:true,
                number: true
            },
            descore:{
                required:true,
                number: true
            }
        },
    });

    function submitHandler() {
        if ($.validate.form()) {
            let scoreTemplates=new Array();
            $("#scoreTemplates option:selected").each(function () {
                scoreTemplates.push($(this).val())
            })
            $.operate.save(prefix + "/evaluate", $('#form-credit-add').serialize()+"&params[scoreTemplates]="+scoreTemplates.toString());
        }
    }
    setData()
    function setData(){
        let url=prefix+"/listScore"
        let params1={"type":"add","isDelete":0}
        let params2={"type":"minus","isDelete":0}
        $.ajax({
            url: url,
            type: 'post',
            cache: false,
            data: params1,
            dataType: "json",
            success: function (response) {
                let arrays = response.data
                var actions = [];
                for (let i = 0; i < arrays.length; i++) {
                    actions.push($("<option value="+arrays[i].creditId+" >"+arrays[i].info +"</option>"))
                }
                $("#addST").append(actions);
            }
        });
        $.ajax({
            url: url,
            type: 'post',
            cache: false,
            data: params2,
            dataType: "json",
            success: function (response) {
                let arrays = response.data
                var actions = [];
                for (let i = 0; i < arrays.length; i++) {
                    actions.push($("<option value="+arrays[i].creditId+" >"+arrays[i].info +"</option>"))
                }
                $("#minusST").append(actions);
            }
        });
    }


</script>
</body>
</html>